--*-----------------------------------------------------------------------------
--
-- SITE_OPTION
--
--*-----------------------------------------------------------------------------
INSERT INTO SITE_OPTION(NAME)
       SELECT 'CONTACT_PHONE3'
 UNION SELECT 'CONTACT_NAME3'
EXCEPT
SELECT NAME
  FROM SITE_OPTION
GO
--*-----------------------------------------------------------------------------
--
-- OPTION_SUMMARY
--
--*-----------------------------------------------------------------------------
ALTER VIEW OPTION_SUMMARY
AS
  SELECT   1 AS ID
         , dbo.GetOptionText('MAIN_PAGE') AS MAIN_PAGE
         , dbo.GetOptionText('SMTP_SERVER') AS SMTP_SERVER
         , dbo.GetOptionText('SMTP_USER_NAME') AS SMTP_USER_NAME
         , dbo.GetOptionText('SMTP_PASSWORD') AS SMTP_PASSWORD
         , dbo.GetOptionInt('SMTP_PORT') AS SMTP_PORT
         , dbo.GetOptionText('ADMIN_EMAIL') AS ADMIN_EMAIL
         , dbo.GetOptionText('DISQUS_DOMAIN') AS DISQUS_DOMAIN
         , dbo.GetOptionText('ADD_THIS_URL') AS ADD_THIS_URL
         , dbo.GetOptionText('CONTACT_PHONE1') AS CONTACT_PHONE1
         , dbo.GetOptionText('CONTACT_NAME1') AS CONTACT_NAME1
         , dbo.GetOptionText('CONTACT_PHONE2') AS CONTACT_PHONE2
         , dbo.GetOptionText('CONTACT_NAME2') AS CONTACT_NAME2
         , dbo.GetOptionText('CONTACT_PHONE3') AS CONTACT_PHONE3
         , dbo.GetOptionText('CONTACT_NAME3') AS CONTACT_NAME3
         , dbo.GetOptionText('AUTHOR') AS AUTHOR
         , dbo.GetOptionText('META_KEYWORDS') AS META_KEYWORDS
         , dbo.GetOptionText('META_DESCRIPTION') AS META_DESCRIPTION
GO
--*----------------------------------------------------------------------------
ALTER TRIGGER ON_OPTION_SUMMARY ON OPTION_SUMMARY INSTEAD OF INSERT, UPDATE
NOT FOR REPLICATION
AS
BEGIN
  SET NOCOUNT ON
  DECLARE
    @main_page         NVARCHAR(MAX)
  , @smtp_server       NVARCHAR(MAX)
  , @smtp_user_name    NVARCHAR(MAX)
  , @smtp_password     NVARCHAR(MAX)
  , @smtp_port         INT
  , @admin_email       NVARCHAR(MAX)
  , @disqus_domain     NVARCHAR(MAX)
  , @add_this_url      NVARCHAR(MAX)
  , @contact_phone1    NVARCHAR(MAX)
  , @contact_name1     NVARCHAR(MAX)
  , @contact_phone2    NVARCHAR(MAX)
  , @contact_name2     NVARCHAR(MAX)
  , @contact_phone3    NVARCHAR(MAX)
  , @contact_name3     NVARCHAR(MAX)
  , @author            NVARCHAR(MAX)
  , @meta_keywords     NVARCHAR(MAX)
  , @meta_description  NVARCHAR(MAX)

  SELECT
           @main_page         = main_page
         , @smtp_server       = smtp_server
         , @smtp_user_name    = smtp_user_name
         , @smtp_password     = smtp_password
         , @smtp_port         = smtp_port
         , @admin_email       = admin_email
         , @disqus_domain     = disqus_domain
         , @add_this_url      = add_this_url
         , @contact_phone1    = contact_phone1
         , @contact_name1     = contact_name1
         , @contact_phone2    = contact_phone2
         , @contact_name2     = contact_name2
         , @contact_phone3    = contact_phone3
         , @contact_name3     = contact_name3
         , @author            = author
         , @meta_keywords     = meta_keywords
         , @meta_description  = meta_description
    FROM inserted

  EXEC dbo.SetOptionText 'MAIN_PAGE'        , @main_page
  EXEC dbo.SetOptionText 'SMTP_SERVER'      , @smtp_server
  EXEC dbo.SetOptionText 'SMTP_USER_NAME'   , @smtp_user_name
  EXEC dbo.SetOptionText 'SMTP_PASSWORD'    , @smtp_password
  EXEC dbo.SetOptionInt  'SMTP_PORT'        , @smtp_port
  EXEC dbo.SetOptionText 'ADMIN_EMAIL'      , @admin_email
  EXEC dbo.SetOptionText 'DISQUS_DOMAIN'    , @disqus_domain
  EXEC dbo.SetOptionText 'ADD_THIS_URL'     , @add_this_url
  EXEC dbo.SetOptionText 'CONTACT_PHONE1'   , @contact_phone1
  EXEC dbo.SetOptionText 'CONTACT_NAME1'    , @contact_name1
  EXEC dbo.SetOptionText 'CONTACT_PHONE2'   , @contact_phone2
  EXEC dbo.SetOptionText 'CONTACT_NAME2'    , @contact_name2
  EXEC dbo.SetOptionText 'CONTACT_PHONE3'   , @contact_phone3
  EXEC dbo.SetOptionText 'CONTACT_NAME3'    , @contact_name3
  EXEC dbo.SetOptionText 'AUTHOR'           , @author
  EXEC dbo.SetOptionText 'META_KEYWORDS'    , @meta_keywords
  EXEC dbo.SetOptionText 'META_DESCRIPTION' , @meta_description
END
GO
